home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / tos / g__~1 / gplibs15.zoo / stdstrea.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-01  |  2.3 KB  |  72 lines

  1. //    This is part of the iostream library, providing input/output for C++.
  2. //    Copyright (C) 1992 Per Bothner.
  3. //
  4. //    This library is free software; you can redistribute it and/or
  5. //    modify it under the terms of the GNU Library General Public
  6. //    License as published by the Free Software Foundation; either
  7. //    version 2 of the License, or (at your option) any later version.
  8. //
  9. //    This library is distributed in the hope that it will be useful,
  10. //    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12. //    Library General Public License for more details.
  13. //
  14. //    You should have received a copy of the GNU Library General Public
  15. //    License along with this library; if not, write to the Free
  16. //    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18. #include <ioprivat.h>
  19. #include <g_config.h>
  20.  
  21. #if _G_NAMES_HAVE_UNDERSCORE
  22. #define UNDERSCORE "_"
  23. #else
  24. #define UNDERSCORE ""
  25. #endif
  26.  
  27. struct _fake_filebuf;
  28.  
  29. extern _fake_filebuf _cin_sbuf, _cout_sbuf, _cerr_sbuf;
  30.  
  31. #if 0 /* defined(__GNUC__) */
  32. // This hack was intended to trick gdb into thinking cin is really a
  33. // istream (and not a _fake_istream), but doesn't seem to work.
  34. #define STR_NAME(TYPE, NAME) TYPE __##NAME asm(UNDERSCORE #NAME)
  35. #else
  36. #define STR_NAME(TYPE, NAME) TYPE NAME
  37. #endif
  38. #define cin CIN
  39. #define cout COUT
  40. #define cerr CERR
  41. #define clog CLOG
  42. #include <iostream.h>
  43. #undef cin
  44. #undef cout
  45. #undef cerr
  46. #undef clog
  47.  
  48. #ifdef __GNUG__
  49. #define PAD 0 /* g++ allows 0-length arrays. */
  50. #else
  51. #define PAD 1
  52. #endif
  53. class _fake_istream {
  54.     _ios_fields base;
  55.     char filler[sizeof(struct istream)-sizeof(struct _ios_fields)+PAD];
  56. };
  57. class _fake_ostream {
  58.     _ios_fields base;
  59.     char filler[sizeof(struct ostream)-sizeof(struct _ios_fields)+PAD];
  60. };
  61.  
  62. #define STD_STR(SBUF, TIE, EXTRA_FLAGS) \
  63.  (streambuf*)&SBUF, TIE, 0, ios::dont_close|ios::skipws|EXTRA_FLAGS, ' ', 0, 6
  64.  
  65. STR_NAME(_fake_ostream, cout)  = { STD_STR(_cout_sbuf, NULL, 0) };
  66. STR_NAME(_fake_ostream, cerr) =
  67.   { STD_STR(_cerr_sbuf, (ostream*)&cout, ios::unitbuf) };
  68. STR_NAME(_fake_istream, cin)  = { STD_STR(_cin_sbuf,  (ostream*)&cout, 0) };
  69.  
  70. /* Only for (partial) compatibility with AT&T's library. */
  71. STR_NAME(_fake_ostream, clog) = { STD_STR(_cerr_sbuf, (ostream*)&cout, 0) };
  72.